﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zor_DAL;
using Zor_Modes;

namespace Zor_Bll
{
    public class AppUsers_Bll
    {
        /// <summary>
        /// 添加App用户
        /// </summary>
        /// <param name="aus"></param>
        /// <returns></returns>
        public static BaseAnswer InserAppUsers(AppUsers aus)
        {
            BaseAnswer bar = AppUsers_DAL.InserAppUsers(aus);
            if (bar.AnswerType == BaseAnswer.Answers.Succee)
                bar.AnswerMeg = "新增成功！";
            else if (bar.AnswerType == BaseAnswer.Answers.Failure)
                bar.AnswerMeg = "新增失败，请重试！";
            return bar;
        }

        /// <summary>
        /// 判断用户是否已注册过(身份证或者手机号)
        /// </summary>
        /// <param name="aus"></param>
        /// <returns></returns>
        public static BaseAnswer GetAppUsersByLoginName(AppUsers aus)
        {
            BaseAnswer bar = new BaseAnswer();
            AppUsers appUser = AppUsers_DAL.GetAppUsersByLoginName(aus);
            if (appUser == null)
            {
                bar.AnswerType = BaseAnswer.Answers.Succee;
            }
            else 
            {
                bar.AnswerType = BaseAnswer.Answers.Failure;
                bar.AnswerMeg = "用户已存在！";
            }
            return bar;
        }

        /// <summary>
        /// App用户登录
        /// </summary>
        /// <param name="us"></param>
        /// <returns></returns>
        public static BaseAnswer GetAppUserByLoginNameAndPass(AppUsers aus)
        {
            BaseAnswer bar = new BaseAnswer();
            AppUsers appUser = AppUsers_DAL.GetAppUserByLoginNameAndPass(aus);
            if (appUser == null)
            {
                bar.AnswerType = BaseAnswer.Answers.Failure;
                bar.AnswerMeg = "用户名密码错误！";
            }
            else if (appUser.AppUser_LoginName == aus.AppUser_LoginName && appUser.AppUser_LoginPassword == aus.AppUser_LoginPassword)
            {
                bar.AppUser = appUser;
                bar.AnswerType = BaseAnswer.Answers.Succee;
                bar.AnswerMeg = "登录成功！";
            }
            return bar;
        }

        public static BaseAnswer UpdateAppUsersPassword(AppUsers aus)
        {
            BaseAnswer bar = AppUsers_DAL.UpdateAppUsersPassword(aus);
            if (bar.AnswerType == BaseAnswer.Answers.Succee)
                bar.AnswerMeg = "修改成功！";
            else if (bar.AnswerType == BaseAnswer.Answers.Failure)
                bar.AnswerMeg = "删除失败，请重试！";
            return bar;
        }
    }
}
